﻿using DXApplicationTangche.UC.成品出库单.service;
using DXApplicationTangche.UC.门店出入库.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.门店出入库
{
    public partial class Form调拨入库确认 : DevExpress.XtraEditors.XtraForm
    {
        public delegate void ClearAllEvents();//定义委托
        public event ClearAllEvents clearAllEvents;//定义事件
        private String inOutCode;
        private String inStoreId;
        private String mnemonic;
        private List<StockInOutDetailDTO> enterUnStockInOutDetailDTOs = new List<StockInOutDetailDTO>();
        private List<StockInOutDetailDTO> enterShowStockInOutDetailDTOs = new List<StockInOutDetailDTO>();
        private List<StockInOutDetailDTO> enterExtraStockInOutDetailDTOs = new List<StockInOutDetailDTO>();
        public Form调拨入库确认()
        {
            InitializeComponent();
        }
        public Form调拨入库确认(
            String inOutCode,
            String inStoreId,
            String mnemonic,
            List<StockInOutDetailDTO> enterStockInOutDetailDTOs,
            List<StockInOutDetailDTO> enterShowStockInOutDetailDTOs,
            List<StockInOutDetailDTO> enterExtraStockInOutDetailDTOs
            )
        {
            InitializeComponent();
            this.inOutCode = inOutCode;
            this.inStoreId = inStoreId;
            this.mnemonic = mnemonic;
            this.buildStockInOutDetailDTOs(
                enterStockInOutDetailDTOs,
                enterShowStockInOutDetailDTOs,
                enterExtraStockInOutDetailDTOs
                );
        }

        private void simpleButton确认入库_Click(object sender, EventArgs e)
        {
            try
            {
                出入库Service.saveStockOutToInConfirm(
                    this.inOutCode,
                    this.inStoreId,
                    this.mnemonic,
                    this.enterShowStockInOutDetailDTOs
                    );
                MessageBox.Show("入库成功");
                this.clearAllEvents();
                this.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("入库失败" + ex.Message);
            }
        }

        /// <summary>
        /// 整理数据
        /// </summary>
        /// <param name="enterStockInOutDetailDTOs"></param>
        /// <param name="enterShowStockInOutDetailDTOs"></param>
        /// <param name="enterExtraStockInOutDetailDTOs"></param>
        private void buildStockInOutDetailDTOs(
            List<StockInOutDetailDTO> enterStockInOutDetailDTOs,
            List<StockInOutDetailDTO> enterShowStockInOutDetailDTOs,
            List<StockInOutDetailDTO> enterExtraStockInOutDetailDTOs
            )
        {
            this.enterUnStockInOutDetailDTOs =
                enterStockInOutDetailDTOs.Except(enterShowStockInOutDetailDTOs).ToList();
            this.enterShowStockInOutDetailDTOs = enterShowStockInOutDetailDTOs;
            this.enterExtraStockInOutDetailDTOs = enterExtraStockInOutDetailDTOs;

            this.gridControl门店调拨入库已扫码.DataSource = this.enterShowStockInOutDetailDTOs;
            this.gridView门店调拨入库已扫码.RefreshData();
            this.gridView门店调拨入库已扫码.BestFitColumns();
            this.gridControl门店调拨入库多出的.DataSource = this.enterExtraStockInOutDetailDTOs;
            this.gridView门店调拨入库多出的.RefreshData();
            this.gridView门店调拨入库多出的.BestFitColumns();
            this.gridControl门店调拨入库未扫码.DataSource = this.enterUnStockInOutDetailDTOs;
            this.gridView门店调拨入库未扫码.RefreshData();
            this.gridView门店调拨入库未扫码.BestFitColumns();
        }
    }
}
